﻿
@{
    Layout = null;
}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>用户登录，用户注册-机加工报价管理系统</title>
    <link href="~/Content/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="~/Content/alertify.min.css" />
    <link rel="stylesheet" href="~/Content/themes/default.min.css" />
    <style>
        html, body {
            height: 100%;
            position: relative;
            overflow: hidden;
        }
    </style>
</head>
<body class="login_b">
    <img src="~/Images/login.jpg" />

    <div class="login">
        <ul><li class="cur dl">登陆</li><li class="zc">注册</li></ul>
        <form id="login" style="display:block;" onsubmit="return onLogin();">
            <div><span>用　户：</span><select name="level_type"><option value="管理员">管理员</option><option value="分管理员">分管理员</option></select></div>
            <div><span>用户名：</span><input type="text" name="username" /></div>
            <div><span>密　码：</span><input type="password" name="password" /></div>
            <p><span></span><input type="submit" value="登陆" /></p>
        </form>
        <form id="reg" onsubmit="return onReg();">
            <div><span>用户名：</span><input type="text" name="username" /></div>
            <div><span>姓　名：</span><input type="text" name="name" /></div>
            <div><span>密　码：</span><input type="password" name="password" /></div>
            <p><span></span><input type="submit" value="确认注册" /></p>
        </form>
    </div>
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/uilts.js"></script>
    <script src="~/Scripts/alertify.min.js"></script>
    <script>
        $('.login li').click(function(){
            $('.login li').removeClass('cur');
            $(this).addClass('cur');
            $('.login form').css("display","none");
            $('.login form').eq($(this).index()).css("display","block");
        });

        function onLogin(){
            var username = $("#login input[name='username']").val().trim();
            if (username == "") {
                alertify.error("用户名不能为空!");
                return false;
            }
            var password = $("#login input[name='password']").val().trim();
            if (password == "") {
                alertify.error("密码不能为空!");
                return false;
            }
            PostApi("/user/checklogin", { username: username, password: password }, function (result) {
                if (result.code == 0) {
                    location.href = "/"
                }
                else {
                    alertify.error(result.ErrorMessage);
                }
            }, function () {
                alertify.error("登录失败!");
            });
            return false;
        }

        function onReg() {
            var username = $("#reg input[name='username']").val().trim();
            if (username == "" || username.length>10) {
                alertify.error("用户名不能为空且不能超过10个字符!");
                return false;
            }
            var password = $("#reg input[name='password']").val().trim();
            if (password == "" || password.length<4) {
                alertify.error("密码不能为空且长度必须在4-10位之间!");
                return false;
            }
            var name = $("#reg input[name='name']").val().trim();
            if (name == "" || name.length > 10) {
                alertify.error("姓名不能为空且不能超过10个字符!");
                return false;
            }

            PostApi("/user/CheckRegister", { username: username, name: name, password: password }, function (result) {
                if (result.code == 0) {
                    alertify.warning("注册成功，请联系系统管理员完成授权后才能进行登录!");
                } else {
                    alertify.error(result.ErrorMessage);
                }
            }, function () {
                alertify.error("注册失败!");
            });
            return false;
        }
    </script>
</body>
</html>
